

<template>
	<view class="goods-list">
		<view v-for="(goods, i) in goodsList" :key="i" @click="gotpDetail(goods)">
			<my-goods :goods="goods"></my-goods>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 请求参数对象
				queryObj: {
					// 查询关键词
					query: '',
					// 商品分类Id
					cid: '',
					// 页码值
					pagenum: 1,
					// 每页显示多少条数据
					pagesize: 10
				},
				goodsList: [],
				total: 0,
				//节流阀
				isLoading:false

			};
		},
		onLoad(options) {
			this.getGoodsList()
		},
		methods: {
			//获取商品列表
			async getGoodsList(cb) {
				this.isLoading = true
				const res = await uni.$http.get('/search/goodsList')
				this.isLoading = false
				
				cb && cb()
				if (res.statusCode === 200) {
					this.goodsList = [...this.goodsList, ...res.data.goods]
					this.total += res.data.total
					console.log(this.total)
				}
			},
			gotpDetail(goods){
				uni.navigateTo({
					url:'/subpkg/goods_detail/goods_detail?goods_id=' + goods.goods_id
				})
			}
		},
		onReachBottom() {
			if (this.isLoading) return
			if (this.total >= 32) return uni.$showMsg('数据加载完毕')
			//让页码值自增1
			this.queryObj.page++
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.queryObj.pagenum = 0
			this.total = 0
			this.isLoading = false
			this.goodsList = []
			console.log("下拉刷新")
			
			this.getGoodsList(() => uni.stopPullDownRefresh())
		}
	}
</script>

<style lang="scss">
	
</style>
